﻿using blackhouse.NemoBlog.Business;
using blackhouse.WebNemo.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace blackhouse.NemoBlog.Web {

    public class DTNemoBlogPost {

        public NemoBlogPost Post { get; private set; }
        public string WellFormedUrl { get; private set; }
        public string ShortTitle { get; private set; }
        public string PublisherName { get; private set; }
        public DTNemoBlogTag[] Tags { get; private set; }
        public string IsoPublishedDate { get; private set; }

        public DTNemoBlogPost(NemoBlogPost post) {
            NemoBlogSettings settings = new NemoBlogSettings(post.ModuleId);
            this.Post = post;
            this.WellFormedUrl = blackhouse.WebNemo.Cms.CmsNemoUrl.AdjustUrlToCurrentSite(this.Post.PostUrl);
            this.PublisherName = WebNemoUtils.GetDisplayUser(this.Post.CreatedBy);
            this.ShortTitle = post.ShortTitle;
            if (String.IsNullOrEmpty(this.ShortTitle))
                this.ShortTitle = post.Title;

            if (settings.UseTagSystem)
                this.Tags = post.Tags.Select(t => new DTNemoBlogTag(t)).ToArray();
            else
                this.Tags = new DTNemoBlogTag[0];
            this.IsoPublishedDate = this.Post.PublishDate.ToString("s");
        }

    }

}